package com.itheima.controller;

import com.itheima.aspect.Log;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import com.itheima.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*学生*/
@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    /**
     * 分页查询学员
     *
     * @param page
     * @return
     */
    @GetMapping
    public Result getStudentList(StudentQueryParam page) {
        PageBean pageBean = studentService.getStudentList(page);
        return Result.success(pageBean);
    }

    /**
     * 添加学员
     *
     * @param student
     * @return
     */
    @Log
    @PostMapping
    public Result insertStudent(@RequestBody Student student) {
        studentService.insertStudent(student);
        return Result.success();
    }

    /**
     * 根据id查询学生
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getStudentById(@PathVariable Integer id) {
        Student student = studentService.getStufentById(id);
        return Result.success(student);
    }

    /**
     * 修改学生信息
     *
     * @param student
     * @return
     */
    @Log
    @PutMapping
    public Result updateStudent(@RequestBody Student student) {
        studentService.updateStudent(student);
        return Result.success();
    }

    /**
     * 批量删除学员
     *
     * @param ids
     * @return
     */
    @Log
    @DeleteMapping("/{ids}")
    public Result deleteStudents(@PathVariable Integer[] ids) {
        studentService.deleteStudents(ids);
        return Result.success();
    }

    /**
     * 违纪处理
     * @param id
     * @param score
     * @return
     */
    @Log
    @PutMapping("/violation/{id}/{score}")
    public Result violationHandle(@PathVariable Integer id, @PathVariable Integer score) {
        studentService.violationHandle(id, score);
        return Result.success();
    }
}
